import java.sql.SQLOutput;
import java.util.Arrays;
import java.util.Scanner;

public class BullandCows {
    //声明机选与中奖数组
    public static int[] computerBull;
    public static int[] jackpotBull;

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        //中奖数字
        computerBull = create();
        System.out.println(Arrays.toString(computerBull));

        //五次机会进行比较
        for (int i = 0; i < 5; i++) {
            System.out.println("你还有" + (5 - i) + "次机会");
            input();
            if (computerBull[i] == jackpotBull[i]) {
                System.out.println("成功");
                break;
            }
        }
    }

    //随机数函数
    public static int random(int min, int max) {
        return (int) (Math.random() * max - min + 1 + min);
    }

    //生成四个不同数的函数
    public static int[] create() {
        int[] bullNum = new int[4];
        for (int i = 0; i < bullNum.length; i++) {
            int num = random(0, 9);
            boolean flag = false;
            for (int j = 0; j < bullNum.length; j++) {
                if (num == bullNum[j]) {
                    flag = true;
                }
            }
            if (flag) {
                i--;
            } else {
                bullNum[i] = num;
            }
        }
        return bullNum;
    }

    //输入函数
    public static int[] input() {
        Scanner scan = new Scanner(System.in);
        jackpotBull = new int[4];
        for (int i = 0; i < 4; i++) {
            while (true) {
                try {
                    System.out.println("请输入第" + (i + 1) + "个数字");
                    jackpotBull[i] = scan.nextInt();
                    break;
                } catch (Exception e) {
                    System.out.println("请重新输入");
                    scan.next();
                }
            }
        }
        System.out.println(Arrays.toString(jackpotBull));
        contrast();
        return jackpotBull;
    }

    //比较函数
    public static void contrast() {
        int all = 0;
        int single = 0;
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                if (computerBull[i] == jackpotBull[j] && i == j) {
                    all++;
                }
            }
        }
        for (int i = 0; i < computerBull.length; i++) {
            for (int j = 0; j < jackpotBull.length; j++) {
                if (computerBull[i] == jackpotBull[j] && i != j) {
                    single++;
                }
            }
        }
        System.out.println(all + "A" + "" + single + "B");
    }

}
